const BaseConfig = require("./webpack.base.config");
const merge = require("webpack-merge");
const webpack = require("webpack");
const path = require("path");
const CpoyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin");
const OptimizeCssAssetsWebpackPlugin = require("optimize-css-assets-webpack-plugin");
module.exports = merge(BaseConfig, {
    output: {
        filename: path.join("static/", "js/[name].[chunkhash].js"),
        path: path.resolve(__dirname, "../dist"),
        publicPath: "./",
        chunkFilename: path.join("static/", "js/[id].[chunkhash].js"),
    },
    module:{
        rules:[
            {
                test: /\.css$/,
                use: ExtractTextWebpackPlugin.extract({
                    fallback: "style-loader",
                    use: ["css-loader", "postcss-loader"]
                })
            },
            {
                test: /\.scss$/,
                use: ExtractTextWebpackPlugin.extract({
                    fallback: "style-loader",
                    use: [ {
                        loader: "css-loader",
                        options: {
                            sourceMap: false,
                        }// 将 CSS 转化成 CommonJS 模块
                    }, {
                        loader: "sass-loader",
                        options: {
                            sourceMap: false,
                        }
                        // 将 Sass 编译成 CSS
                    }]
                })
            },
        ]
    },
    plugins:[
        new ExtractTextWebpackPlugin({
           filename: path.join("static/", "css/[name].[contenthash].css")
        }),
        new OptimizeCssAssetsWebpackPlugin({
            cssProcessorOptions:{
                safe: true
            }
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name:"commons",
            filename:path.join("static/", "js/[name].[chunkhash].js"),
            chunkFilename: ["commons"]
        }),
        // new CpoyWebpackPlugin([
        //     {
        //         from: path.resolve(__dirname, "../common"),
        //         to : "static",
        //         ignore:['.*']
        //     }
        // ])
    ]
});
